<?php
	set_include_path (PHPPATH);
	require_once 'MDB2.php';
	/**
	 * 
	 * The favorite controller
	 * @author Tri
	 *
	 */
	class favorite extends Application 
	{
		/**
		 * 
		 * Constructor
		 */
		function __construct(&$tmpl)
		{			
			$this->tmpl = &$tmpl;		
		}

		/**
		 * 
		 * Default action
		 */
		function index()
		{	
			$this->assign("currentView", "favorite");
			
			
			//$userId = $_SESSION['uid'];
			$_SESSION['sid'] = session_id();
			$userId = $this->getLoggedUser();
			
			if($userId == 0) {
				$logged = 0;
				$page = "login";
				$title = "Login";
				$this->assign("loginVisible", 1);
			}
			else {
				$logged = 1;
				$page = "home";
				$title = "Favorite";
				$this->assign("logoutVisible", 1);
				
				$this->assign("imagesPath", $this->loadResources('images'));
            	$this->assign("productPath", $this->loadResources('product'));
				$productModel = $this->getModel('ProductModel');
	            $rowProduct = $productModel->getFavProductsByUserId($userId);
	            $this->assign("products", $rowProduct);
	            $this->assign("products_count", count($rowProduct));				
			}
			
			
			$this->assign("title", $title);
			$this->assign("logged",$logged);
			$this->assign("page", $page);
			$this->assign("loggedId", $userId);
			$this->loadTemplate('favorite_page');
		}
	}
?>